/*
	Copyright (c) 2004-2009, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dijit._base.popup"]){
dojo._hasResource["dijit._base.popup"]=true;
dojo.provide("dijit._base.popup");
dojo.require("dijit._base.focus");
dojo.require("dijit._base.place");
dojo.require("dijit._base.window");
dijit.popup=new function(){
var _1=[],_2=1000,_3=1;
this.prepare=function(_4){
var s=_4.style;
s.visibility="hidden";
s.position="absolute";
s.top="-9999px";
if(s.display=="none"){
s.display="";
}
dojo.body().appendChild(_4);
};
this.open=function(_5){
var _6=_5.popup,_7=_5.orient||(dojo._isBodyLtr()?{"BL":"TL","BR":"TR","TL":"BL","TR":"BR"}:{"BR":"TR","BL":"TL","TR":"BR","TL":"BL"}),_8=_5.around,id=(_5.around&&_5.around.id)?(_5.around.id+"_dropdown"):("popup_"+_3++);
var _9=dojo.create("div",{id:id,"class":"dijitPopup",style:{zIndex:_2+_1.length,visibility:"hidden",left:"0px",top:"0px"},dijitPopupParent:_5.parent?_5.parent.id:""},dojo.body());
dijit.setWaiRole(_9,"presentation");
var s=_6.domNode.style;
s.display="";
s.visibility="";
s.position="";
s.top="0px";
_9.appendChild(_6.domNode);
var _a=new dijit.BackgroundIframe(_9);
var _b=_8?dijit.placeOnScreenAroundElement(_9,_8,_7,_6.orient?dojo.hitch(_6,"orient"):null):dijit.placeOnScreen(_9,_5,_7=="R"?["TR","BR","TL","BL"]:["TL","BL","TR","BR"],_5.padding);
_9.style.visibility="visible";
var _c=[];
var _d=function(){
for(var pi=_1.length-1;pi>0&&_1[pi].parent===_1[pi-1].widget;pi--){
}
return _1[pi];
};
_c.push(dojo.connect(_9,"onkeypress",this,function(_e){
if(_e.charOrCode==dojo.keys.ESCAPE&&_5.onCancel){
dojo.stopEvent(_e);
_5.onCancel();
}else{
if(_e.charOrCode===dojo.keys.TAB){
dojo.stopEvent(_e);
var _f=_d();
if(_f&&_f.onCancel){
_f.onCancel();
}
}
}
}));
if(_6.onCancel){
_c.push(dojo.connect(_6,"onCancel",null,_5.onCancel));
}
_c.push(dojo.connect(_6,_6.onExecute?"onExecute":"onChange",null,function(){
var _10=_d();
if(_10&&_10.onExecute){
_10.onExecute();
}
}));
_1.push({wrapper:_9,iframe:_a,widget:_6,parent:_5.parent,onExecute:_5.onExecute,onCancel:_5.onCancel,onClose:_5.onClose,handlers:_c});
if(_6.onOpen){
_6.onOpen(_b);
}
return _b;
};
this.close=function(_11){
while(dojo.some(_1,function(_12){
return _12.widget==_11;
})){
var top=_1.pop(),_13=top.wrapper,_14=top.iframe,_15=top.widget,_16=top.onClose;
if(_15.onClose){
_15.onClose();
}
dojo.forEach(top.handlers,dojo.disconnect);
if(!_15||!_15.domNode){
return;
}
this.prepare(_15.domNode);
_14.destroy();
dojo.destroy(_13);
if(_16){
_16();
}
}
};
}();
dijit._frames=new function(){
var _17=[];
this.pop=function(){
var _18;
if(_17.length){
_18=_17.pop();
_18.style.display="";
}else{
if(dojo.isIE){
var _19=dojo.config["dojoBlankHtmlUrl"]||(dojo.moduleUrl("dojo","resources/blank.html")+"")||"javascript:\"\"";
var _1a="<iframe src='"+_19+"'"+" style='position: absolute; left: 0px; top: 0px;"+"z-index: -1; filter:Alpha(Opacity=\"0\");'>";
_18=dojo.doc.createElement(_1a);
}else{
_18=dojo.create("iframe");
_18.src="javascript:\"\"";
_18.className="dijitBackgroundIframe";
}
_18.tabIndex=-1;
dojo.body().appendChild(_18);
}
return _18;
};
this.push=function(_1b){
_1b.style.display="none";
_17.push(_1b);
};
}();
dijit.BackgroundIframe=function(_1c){
if(!_1c.id){
throw new Error("no id");
}
if(dojo.isIE||dojo.isMoz){
var _1d=dijit._frames.pop();
_1c.appendChild(_1d);
if(dojo.isIE<7){
dojo.style(_1d,{width:_1c.offsetWidth+"px",height:_1c.offsetHeight+"px"});
this._conn=dojo.connect(_1c,"onresize",function(){
dojo.style(_1d,{width:_1c.offsetWidth+"px",height:_1c.offsetHeight+"px"});
});
}else{
dojo.style(_1d,{width:"100%",height:"100%"});
}
this.iframe=_1d;
}
};
dojo.extend(dijit.BackgroundIframe,{destroy:function(){
if(this._conn){
dojo.disconnect(this._conn);
this._conn=null;
}
if(this.iframe){
dijit._frames.push(this.iframe);
delete this.iframe;
}
}});
}
